package com.xiaobing.common.base;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;

/**
 * Entity基类 (继承基础分页类)
 *
 * @author xulk
 */

@Data
public class BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;


    // 主键
    @TableId(type = IdType.ASSIGN_ID)
    private Long id;


    /**
     * 创建者
     */
    @TableField(value = "create_by", fill = FieldFill.INSERT)
    private String createBy;

    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;

    /**
     * 更新者
     */
    @TableField(value = "update_by", fill = FieldFill.INSERT_UPDATE)
    private String updateBy;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

    /**
     * 备注
     */
    @TableField(exist = false)
    private String remark;


    // 删除逻辑  // 0 未删除，1 已删除
    @TableLogic
    private Integer delFlag;


    /**
     * 分页参数 大小
     */
    @TableField(exist = false)
    @JsonIgnore
    private int pageSize;

    /**
     * 分页参数 页码
     */
    @TableField(exist = false)
    @JsonIgnore
    private int pageNum;


    // 构造函数，默认值处理
    public BaseEntity() {
        this.pageSize = 10;
        this.pageNum = 1;
    }

    // 构造函数，允许设置初始值
    public BaseEntity(int pageSize, int pageNum) {
        /*if( pageSize <= 0 ){
            this.pageSize =   10 ;
        }else if( pageSize > 999 ){
            this.pageSize = 100 ;
        }else {
            this.pageSize =  pageSize;
        }*/
        this.pageSize = (pageSize <= 0) ? 10 : (pageSize > 999) ? 100 : pageSize;
        this.pageNum = (pageNum <= 0) ? 1 : pageNum;
    }


}
